package com.xyxe.domain.strategy.model.entity;

import com.xyxe.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * 策略实体
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class StrategyEntity {
    private Long strategyId;
    private String strategyDesc;
    /**
     * 抽奖规则模型  rule_weight,rule_blacklist
     */
    private String ruleModels;

    // 将rule_models分隔开
    public String[] ruleModels() {
        if (StringUtils.isBlank(ruleModels)) {
            return null;
        }
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight() {
        String[] ruleModels = ruleModels();
        if (ruleModels == null) return null;
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel)) {
                return ruleModel;
            }
        }
        return null;
    }

}
